package gupao.concurrency.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
public class ThreadPoolRunState {
//    private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0));
    private static final int COUNT_BITS = Integer.SIZE - 3;
    private static final int CAPACITY   = (1 << COUNT_BITS) - 1;
    private static final int RUNNING    = -1 << COUNT_BITS;
    private static final int SHUTDOWN   =  0 << COUNT_BITS;
    private static final int STOP       =  1 << COUNT_BITS;
    private static final int TIDYING    =  2 << COUNT_BITS;
    private static final int TERMINATED =  3 << COUNT_BITS;

    public static void main(String[] args) {
        printRunStates();
        printWorkCountCapacity();

    }

    static void printRunStates(){
        log.info("RUNNING: {}， 二进制：{}", RUNNING,intTo32Binary(RUNNING));
        log.info("SHUTDOWN: {}， 二进制：{}", SHUTDOWN, intTo32Binary(SHUTDOWN));
        log.info("STOP: {}， 二进制：{}", STOP, intTo32Binary(STOP));
        log.info("TIDYING: {}， 二进制：{}", TIDYING, intTo32Binary(TIDYING));
        log.info("TERMINATED: {}， 二进制：{}", TERMINATED, intTo32Binary(TERMINATED));
    }

    static void printWorkCountCapacity(){
        log.info("CAPACITY: {}， 二进制：{}", CAPACITY, intTo32Binary(CAPACITY));
    }

    static String intTo32Binary(int i){
        String binaryStr = Integer.toBinaryString(i);
        while(binaryStr.length() < 32){
            binaryStr = "0"+binaryStr;
        }
        return binaryStr;
    }


}
